[C#]Problem with dynamic create tabPages in TabControl

Posted by mirt on Stack Overflow See other posts from Stack Overflow or by mirt
Published on 2010-03-25T09:28:56Z Indexed on 2010/03/25 9:33 UTC
Read the original article Hit count: 525

Filed under:
|
|
|

Hello, I want to create dynamic tabPages in TabControl. In each tabPage I create dataGridView and i want to fill the entire space of each tabPage with this dataGrid. Here is code, where i do this:

private void tabControlMutants_SelectedIndexChanged(object sender, EventArgs e)
        {
            DataGridView dgw = new DataGridView(); 

DataGridViewTextBoxColumn testCaseCol = new System.Windows.Forms.DataGridViewTextBoxColumn(); DataGridViewTextBoxColumn resultCol = new System.Windoows.Forms.DataGridViewTextBoxColumn(); // // dataGridView1 // dgw.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; dgw.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { testCaseCol, resultCol}); dgw.Location = new System.Drawing.Point(3, 3); dgw.Name = "dataGridView1"; dgw.AutoSize = true; dgw.Dock = System.Windows.Forms.DockStyle.Fill; dgw.TabIndex = 0; // // TestCaseColumn // testCaseCol.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; testCaseCol.HeaderText = "Test Case"; testCaseCol.Name = "TestCaseColumn"; // // ResultColumn // resultCol.HeaderText = "Result"; resultCol.Name = "ResultColumn"; tabControlMutants.TabPages[(sender as TabControl).SelectedIndex].Controls.Add(dgw); ((System.ComponentModel.ISupportInitialize)(dgw)).EndInit(); //fill dataGridView }

But it doesn't work, becouse when i resize the main window, data gridView doesn.t change its size (although the dock property is set to fill). Any ideas?

© Stack Overflow or respective owner

Related posts about c#

Related posts about winforms